# Comment/uncomment the following line to enable/disable debugging
DEBUG = y

ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DMRP_DEBUG    # "-O" is needed to expand inlines
else
  DEBFLAGS = -O2
endif

EXTRA_CFLAGS += $(DEBFLAGS) -I$(LDDINC)
EXTRA_CFLAGS += -I$(PWD)/include

TARGET = mrp

ifneq ($(KERNELRELEASE),)

obj-m	:= mrp.o

mrp-objs := src/mrp_main.o \
			src/mrp_message_processing_thread.o \
			src/mrp_applicant.o \
			src/mrp_registrar.o \
			src/mrp_leave_all.o \
			src/mrp_periodic_transmission.o \
			src/mrp_attribute.o \
			src/mrp_mrpdu.o \
			src/mrp_port.o \
			src/mrp_state_machine.o \
			src/mrp_timer.o \
			src/mrp_iterator.o \
			src/mrp_attribute_properties.o \
			src/mrp_map.o
			
else

# KERNELDIR ?= /lib/modules/$(shell uname -r)/build
KERNELDIR ?= /usr/src/linux
PWD       := $(shell pwd)

modules:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD) modules

endif

install:
	install -d $(INSTALLDIR)
	install -c $(TARGET).o $(INSTALLDIR)

clean:
	rm -rf src/*.o *.o src/*~ *~ core .depend .*.cmd src/*.ko *.ko *.mod.c .tmp_versions

depend .depend dep:
	$(CC) $(CFLAGS) -M *.c > .depend

ifeq (.depend,$(wildcard .depend))
include .depend
endif

